//
//  DealerAddressViewController.m
//  WDFans
//
//  Created by Zhihong Yuan on 2/13/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "DealerAddressViewController.h"
#import "DealerAddressAnnotation.h"
#import "WDDealer.h"

@interface DealerAddressViewController ()

- (void)loadMapView;

@end

@implementation DealerAddressViewController

@synthesize myMapView;
@synthesize dealer;

#pragma mark - my own methods

- (void)loadMapView
{
    //default to soochow
    MKCoordinateRegion myLoction;
    myLoction.center.latitude = self.dealer.lattitude;
    myLoction.center.longitude = self.dealer.longitude;
    myLoction.span.latitudeDelta = 0.1;
    myLoction.span.longitudeDelta = 0.1;
    [self.myMapView setRegion:myLoction animated:YES];
}

#pragma mark - View lifecycle

- (void)dealloc
{
    [dealer release];
    [myMapView release];
    [super dealloc];
}


- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"经销商地址";
    [self setBackgroundImageViewForTabView];
    [self loadMapView];
    DealerAddressAnnotation *dealerAnnotation = [[DealerAddressAnnotation alloc] initWithDealer:self.dealer];
    [self.myMapView addAnnotation:dealerAnnotation];
    [dealerAnnotation release];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.myMapView = nil;
}
#pragma mark -
#pragma mark MKMapViewDelegate methods
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString *annotationIdentifier = @"annotationIdentifier";
	MKPinAnnotationView* pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
	if (!pinView)
	{
		// if an existing pin view was not available, create one
		pinView = [[[MKPinAnnotationView alloc]
					initWithAnnotation:annotation reuseIdentifier:annotationIdentifier] autorelease];
		pinView.animatesDrop = YES;
		pinView.canShowCallout = YES;
	}
    pinView.annotation = annotation;
	return pinView;
}
@end
